package com.hrp.service;

import com.hrp.hrpdao.AccountsReceivableDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019-05-09.
 */
@Service
public class AccountsReceivableService {

    private static final Logger logger = LoggerFactory.getLogger(AccountsReceivableService.class);

    @Autowired
    private AccountsReceivableDao accountsReceivableDao;

    public Map<String, Object> getAccountsReceivableByPage(Integer page, Integer rows, String startTime, String endTime,String receiverIdStr) {

        Map<String,String> params = new HashMap<>();
        params.put("page",""+page+"");
        params.put("rows",""+rows+"");
        params.put("startTime",""+startTime+"");
        params.put("endTime",""+endTime+"");
        params.put("receiverIdStr",""+receiverIdStr+"");

        Map<String, Object> jsonMap = new HashMap<String, Object>();//定义map
        try{
            List<Map<String,Object>> lists = accountsReceivableDao.getAccountsReceivableByPage(params);

            jsonMap.put("total", lists.get(0).get("taotalCount"));//total键 存放总记录数，必须的
            jsonMap.put("rows", lists);//rows键 存放每页记录 list
            return jsonMap;
        }catch (Exception e) {
            e.printStackTrace();
            logger.info("获取分页账期数据失败");
            return jsonMap;
        }
    }

    public List<Map<String,Object>> getdatagridMergeCells(String startTime,String endTime,String receiverIdStr) {
        Map<String,String> params = new HashMap<>();
       // params.put("page",""+page+"");
       // params.put("rows",""+rows+"");
       // params.put("sort",""+sort+"");
       // params.put("order",""+order+"");
        params.put("startTime",""+startTime+"");
        params.put("endTime",""+endTime+"");
        params.put("receiverIdStr",""+receiverIdStr+"");

        List<Map<String,Object>> lists= new ArrayList<>();
        try{
            lists = accountsReceivableDao.getdatagridMergeCells(params);

            //jsonMap.put("total", lists.get(0).get("taotalCount"));//total键 存放总记录数，必须的
            //jsonMap.put("rows", lists);//rows键 存放每页记录 list
            return lists;
        }catch (Exception e) {
            e.printStackTrace();
            logger.info("获取分页账期数据失败");
            return lists;
        }
    }
}
